package edu.xust.web.controller;

import edu.xust.config.*;
import edu.xust.core.InitMapping;
import edu.xust.dto.BaseDto;
import edu.xust.dto.MessageEnum;
import edu.xust.entity.Drivers;
import edu.xust.entity.YunShu;
import edu.xust.page.PageInfo;
import edu.xust.service.DriversService;

/**
 * 运输管理
 */
@Controller("/yunshuController")
public class YunshuController {

    @Resource
    DriversService driversService;
    /**
     * 查询所有运输订单
     * @return
     */
    @RequestMapping("/getAllYunshu")
    public String getAllYunshu(){
      return MessageEnum.FINDALLPOSTORDERS.getMessage();
    }


    /**
     * 根据id查询单个司机
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/getDriverById/{id}")
    @ResponseBody
    public BaseDto getDriverById(String id) throws Exception {
        BaseDto driverById = driversService.getDriverById(id);
        return  driverById;
    }

    /**
     * 根据司机编号查询货单信息
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/getDriversWithOrder/{id}")
    @ResponseBody
    public BaseDto getDriversWithOrder(String id) throws Exception {
        BaseDto driverById = driversService.getDriversWithOrder(id);
        return  driverById;
    }


    /**
     * Json格式进行传输/Logistis_Manage/WEB-INF/classes/config.xml'
     * @param YunShu
     * @return
     */
    @RequestMapping("/chaXunAll")
    @ResponseBody
    public BaseDto chaXun(@RequestBody YunShu YunShu) {
        System.out.println(YunShu);
        BaseDto baseDto = new BaseDto(MessageEnum.FINDALLPOSTORDERS, YunShu);
        return baseDto;
    }

    @RequestMapping("/getAllDriversByPage")
    @ResponseBody
    public BaseDto getAllDriversByPage(@RequestBody PageInfo pageInfo) throws Exception {
        BaseDto driversByPage = driversService.getDriversByPage(pageInfo);

        return driversByPage;
    }

    /**
     * 添加司机
     * @param drivers
     * @return
     * @throws Exception
     */
    @RequestMapping("/addDrivers")
    @ResponseBody
    public BaseDto addDrivers(@RequestBody Drivers drivers) throws Exception{

        driversService.addDrivers(drivers);

        BaseDto dto = new BaseDto(MessageEnum.ADDSTUDENTSUCCESS,drivers);
        return  dto;

    }

    /**
     * 修改司机
     * @param drivers
     * @return
     * @throws Exception
     */
    @RequestMapping("/editDriver")
    @ResponseBody
    public BaseDto editDriver(@RequestBody Drivers drivers) throws Exception{

        driversService.editDrivers(drivers);

        BaseDto dto = new BaseDto(MessageEnum.ADDSTUDENTSUCCESS,drivers);
        return  dto;
    }

    /**
     * 根据id删除司机
     * @param id
     * @return
     */
    @RequestMapping("/deleteDriverById/{id}")
    @ResponseBody
    public BaseDto deleteDriverById(String id) throws Exception {
        BaseDto driverById = driversService.deleteDrivers(id);
        return  driverById;
    }




}

